﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Xmart.Action
{
    public class ActionResult : IActionResult
    {
        /// <summary>
        /// 消息
        /// </summary>
        public string Message
        {
            get { return msgBuilder.ToString(); }
            set { msgBuilder.AppendLine(value); }
        }
        /// <summary>
        /// 状态
        /// </summary>
        public int State { get; set; }

        /// <summary>
        /// 数据
        /// </summary>
        public object Data { get; set; }

        protected StringBuilder msgBuilder = new StringBuilder();

        /// <summary>
        /// 清除消息
        /// </summary>
        public void MsgClear()
        {
            msgBuilder.Clear();
        }

        /// <summary>
        /// 添加消息
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="args"></param>
        public void MsgAppend(string msg, params object[] args)
        {
            msgBuilder.AppendFormat(msg, args);
        }

        /// <summary>
        /// 添加行
        /// </summary>
        /// <param name="msg"></param>
        public void MsgAppendLine(string msg)
        {
            msgBuilder.AppendLine(msg);
        }

        /// <summary>
        /// 是否成功
        /// </summary>
        public bool Success { get; set; }


        public T GetData<T>()
        {
            return Xmart.Common.DataUtils.To<T>(Data);
        }
    }
}
